// JScript source code

// Below loads Page.xaml
function createSilverlight()
{
	Silverlight.createObjectEx({
		source: "Page.xaml",
		parentElement: document.getElementById("SilverlightControlHost"),
		id: "SilverlightControl",
		properties: 
		{
			width: "100%",
			height: "100%",
			version: "1.1",
			isWindowless: "true",
			background: "#000000",
			enableHtmlAccess: "true"
		},
		
		events: { onLoad: OnLoaded }
	});
	   
	// Do onload stuff
	function OnLoaded(sender, args)
	{
	    // Get reference to silverlight control
        var silverlightControl = document.getElementById('SilverlightControl');
        
        //Give keyboard focus to the Silverlight control
        if (silverlightControl)
        {
            silverlightControl.focus();
        }
        
        // Onload call the method that sends the SL control size to the .Net code
        CallScriptable();
	}
	      
	// Send the SL control size to the .Net code
    function CallScriptable()
    {
        // Get the SL control instance
        var silverlightControl = document.getElementById('SilverlightControl');
        
        // Get the SL control width and height
	    var slWidth = silverlightControl.offsetWidth;
	    
	    var slHeight = silverlightControl.offsetHeight;
    
        // Call the .Net code with the SL control size passed over
	    silverlightControl.Content.JSToDotNet.getSLControlSize(slWidth, slHeight);
    
        // Call from .Net code to JS
	    silverlightControl.Content.JSToDotNet.DotNetToJSEvent = doMessage;
    } 
    
    // Function triggered from .NET code
    function doMessage(_sender, _e)
    {
        alert(_e);
    }
}